home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / gcoope10.zip / UNSIGNED.C < prev    next >
Text File  |  1994-07-22  |  3KB  |  159 lines

  1.  
  2. /*
  3.  
  4.     Unsigned class definition   7/16/94 by Brian Lee Price
  5.  
  6.     This is a flag class.
  7.  
  8.     Compatible with experimental strong typing option
  9.  
  10.     Released as Public Domain   July, 1994.
  11.  
  12. */
  13.  
  14. #if sizeof(unsigned short) > sizeof(tag)
  15. #error INVALID TYPE SIZE FOR TAG
  16. #endif
  17.  
  18. #define CLASS Unsigned
  19.  
  20. #include "gcoope10.h"
  21.  
  22. #include <stdio.h>
  23.  
  24. object CLASS;
  25.  
  26. extern object String;
  27. extern object Char;
  28. extern object ShortInt;
  29. extern object LongInt;
  30.  
  31. USEGEN(changeVal);
  32. USEGEN(valueOf);
  33. USEGEN(asString);
  34. USEGEN(asHexStr);
  35. USEGEN(asChar);
  36. USEGEN(asShortInt);
  37. USEGEN(asLongInt);
  38. USEGEN(asUnsigned);
  39.  
  40. cmethod object m4New(object instance, unsigned short initVal)
  41. {
  42. if(((objHndl *) &instance)->fext)
  43.     {
  44.     unsigned short * ivptr;
  45.     if(NULL==(ivptr=getIVptr(instance))) return 0;
  46.     *ivptr=initVal;
  47.     }
  48. else
  49.     {
  50.     ((objHndl *) &instance)->fext=(tag)instance | ~SIGNMASK;
  51.     (tag) instance=0;
  52.     (unsigned short) instance=initVal;
  53.     }
  54. return instance;
  55. }
  56.  
  57.  
  58. imethod object m4changeVal(object instance, unsigned short newVal)
  59. {
  60. if(instance>=0)
  61.     {
  62.     unsigned short * ivptr;
  63.     if(NULL==(ivptr=getIVptr(instance))) return FUNCFAIL;
  64.     *ivptr=newVal;
  65.     }
  66. else (unsigned short) instance=newVal;
  67. return FUNCOKAY;
  68. }
  69.  
  70.  
  71. imethod unsigned short m4valueOf(object instance)
  72. {
  73. if(instance>=0)
  74.     {
  75.     unsigned short * ivptr;
  76.     ivptr=getIVptr(instance);
  77.     return *ivptr;
  78.     }
  79. else return (unsigned short) instance;
  80. }
  81.  
  82.  
  83. imethod object m4asString(object instance)
  84. {
  85. char strBuf[16];
  86. unsigned short a;
  87.  
  88. if(instance>=0) a=*((unsigned short *) getIVptr(instance));
  89. else a=(unsigned short) instance;
  90. sprintf(strBuf,"%ud", a);
  91. return g(New)(String,strBuf);
  92. }
  93.  
  94.  
  95. imethod object m4asHexStr(object instance)
  96. {
  97. char strBuf[16];
  98. unsigned short a;
  99.  
  100. if(instance>=0) a=*((unsigned short *) getIVptr(instance));
  101. else a=(unsigned short) instance;
  102. sprintf(strBuf, "%x", a);
  103. return g(New)(String,strBuf);
  104. }
  105.  
  106.  
  107. imethod object m4asChar(object instance)
  108. {
  109. unsigned short a;
  110.  
  111. if(instance>=0) a=*((unsigned short *) getIVptr(instance));
  112. else a=(unsigned short) instance;
  113. return g(New)(Char,(char) a);
  114. }
  115.  
  116.  
  117. imethod object m4asLongInt(object instance)
  118. {
  119. unsigned short a;
  120.  
  121. if(instance>=0) a=*((unsigned short *) getIVptr(instance));
  122. else a=(unsigned short) instance;
  123. return g(New)(LongInt,(long) a);
  124. }
  125.  
  126.  
  127. imethod object m4asShortInt(object instance)
  128. {
  129. unsigned short a;
  130.  
  131. if(instance>=0) a=*((unsigned short *) getIVptr(instance));
  132. else a=(unsigned short) instance;
  133. return g(New)(ShortInt,(short) a);
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140. CLASS_INSTALL
  141. {
  142. stat x=FUNCFAIL;
  143.  
  144. if(END==(CLASS=g(New)(Class, 0, sizeof(unsigned short), END))) goto end;
  145. if(addGMthd(CLASS, New, (method) m4New)) goto end;
  146. if(addGMthd(CLASS, GEN(changeVal), (method) m4changeVal)) goto end;
  147. if(addGMthd(CLASS, GEN(valueOf), (method) m4valueOf)) goto end;
  148. if(addGMthd(CLASS, GEN(asString), (method) m4asString)) goto end;
  149. if(addGMthd(CLASS, GEN(asHexStr), (method) m4asHexStr)) goto end;
  150. if(addGMthd(CLASS, GEN(asChar), (method) m4asChar)) goto end;
  151. if(addGMthd(CLASS, GEN(asLongInt), (method) m4asLongInt)) goto end;
  152. if(addGMthd(CLASS, GEN(asShortInt), (method) m4asShortInt)) goto end;
  153. if(addGMthd(CLASS, GEN(asUnsigned), bounceBack)) goto end;
  154. x=FUNCOKAY;
  155.  
  156. end:
  157. return x;
  158. }
  159.